package models.dao;

import java.util.ArrayList;
import java.util.List;

import models.entities.Shop;
import models.repo.IRepository;

import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ShopDAO {

	@Autowired
	private IRepository repo;
	
	@Autowired
	private CommonDAO commonDAO;
	
	public Shop createShop(Shop shop) throws Exception {
		if (shop == null) {
			throw new IllegalArgumentException("shop");
		}
		if (shop.getShopCode() != null)
			shop.setShopCode(shop.getShopCode().toUpperCase());

		repo.create(shop);
		
		return repo.getEntityById(Shop.class, shop.getShopId());
	}

	public void deleteShop(Shop shop) throws Exception {
		if (shop == null) {
			throw new IllegalArgumentException("shop");
		}
		repo.delete(shop);
		
	}

	public Shop getShopById(Long id) throws Exception {
		return repo.getEntityById(Shop.class, id);
	}
	
	public void updateShop(Shop shop) throws Exception {
		if (shop == null) {
			throw new IllegalArgumentException("shop");
		}
		shop.setUpdateDate(commonDAO.getSysDate());
		repo.update(shop);
	}
}
